<?php
/** .-------------------------------------------------------------------
 * |  Software: [HDCMS framework]
 * |      Site: www.hdcms.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace web\admin\controller;


class Article extends Common{
    protected $db;
	public function __construct()
	{
		parent::__construct();
		$this->db = new \system\model\Article();
	}
//	文章首页
	public function index(){
		$data = $this->db->get();
//		载入模板
		View::with('data',$data)->make();
	}
	//添加
	public function add(){
		if (IS_POST){
			if ($this->db->store()){
				message('添加成功','','success');
			}
			message($this->db->getError(),'back','error');
		}
		//获取所属分类数据
		$cateData = Data::tree(Db::table("category")->get(),'cname');
		//获取标签数据
		$tagData = Db::table("tag")->get();
		View::with('cateData',$cateData)->with('tagData',$tagData)->make();

	}
//	删除
	public function del(){
		$aid = q('get.aid',0,'intval');
		//把当前aid这条数据删除
		$this->db->where('aid',$aid)->delete();
		Db::table("article_data")->where('article_aid',$aid)->delete();
		Db::table("article_tag")->where('article_aid',$aid)->delete();
		message('删除成功',u('index'),'success');
	}
}
